package com.mock.action.organisation.directorate;

import java.util.ArrayList;
import java.util.List;

import com.mock.action.AbstractAction;
import com.mock.action.organisation.department.DepartmentAction;
import com.mock.dao.AddressDao;
import com.mock.dao.BusinessTypeDao;
import com.mock.dao.ContactDao;
import com.mock.dao.CountryDao;
import com.mock.dao.DirectorateDao;
import com.mock.dao.OrganisationDao;
import com.mock.dao.impl.AddressDaoImp;
import com.mock.dao.impl.BusinessTypeDaoImpl;
import com.mock.dao.impl.ContactDaoImpl;
import com.mock.dao.impl.CountryDaoImpl;
import com.mock.dao.impl.DirectorateDaoImp;
import com.mock.dao.impl.OrganisationDaoImpl;
import com.mock.model.Address;
import com.mock.model.BusinessType;
import com.mock.model.Contact;
import com.mock.model.Country;
import com.mock.model.Directorate;
import com.mock.model.Organisation;

public class EditDirectorateAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4404341737926657180L;
	
	public String execute(){
		
		if(directorateId == null) return ERROR;
		directorate = directorateDao.getById(Directorate.class, directorateId);
		countries = countryDao.getAllCountry();
		idSelected = directorateId;
		organisationId = directorate.getOrganisation().getOrganisationId();
		return SUCCESS;
	}
	public String update(){
		//System.out.println("==========="+ organisationId + " --- "+ directorateId);
		directorate = directorateDao.getById(directorateId);
		directorate.setDirectorateName(directorateName);
		directorate.setDirectorateShortDescription(directorateShortDescription);
		Contact contact = contactDao.getById(leadContactId);
		directorate.setContact(contact);
		directorate.setAddressName1(addressLine1);
		directorate.setAddressName2(addressLine2);
		directorate.setAddressName3(addressLine3);
		directorate.setPostcode(postcode);
		directorate.setTown(city);
		directorate.setCounty(county);
		Country country2 = countryDao.getById(country);
		directorate.setCountry(country2);
		BusinessType businessType = businessTypeDao.getById(businessId);
		directorate.setBusinessType(businessType);
		directorate.setDirectorateFullDescription(directorateFullDescription);
		directorate.setPhoneNumber(phoneNumber);
		directorate.setFax(fax);
		directorate.setEmail(email);
		directorate.setWebAddress(webAddress);
		directorate.setCharityNumber(charityNumber);
		directorate.setCompanyNumber(companyNumber);
		/*Organisation organisation = organisationDao.getById(organisationId);
		directorate.setOrganisation(organisation);*/

		directorateDao.update(directorate);
		
		
		return SUCCESS;
	}
	public String create(){
		gernerateData();
		return SUCCESS;
	}
	public void gernerateData(){
		
		directorates = directorateDao.getAllDirectorate();
		businessTypes = businessTypeDao.getAlBusinessType();
		contacts = contactDao.getAllContact();
		countries = countryDao.getAllCountry();
		
	}
	public String setMark(){
		
		directorateId = Long.valueOf(getRequest().getParameter("directorateId"));
		DirectorateDao directorateDao = new DirectorateDaoImp();
		Directorate directorate = directorateDao.getById(directorateId);
		directorate.setActive(false);
		organisationId = directorate.getOrganisation().getOrganisationId();
		directorateDao.update(directorate);
		return SUCCESS;
	}

	
	// thuoc tinh
	private static Long idSelected;
	private String directorateName;
	private String directorateShortDescription;
	private Long contactId;
	private Long leadContactId;
	private Long organisationId;
	private String addressLine1;
	private String addressLine2;
	private String addressLine3;
	private String postcode;
	private String city;
	private String county;
	private Long country;
	private Long businessId;
	private String directorateFullDescription;
	private String phoneNumber;
	private String fax;
	private String email;
	private String webAddress;
	private String charityNumber;
	private String companyNumber;
	private Long directorateId;
	private Directorate directorate;
	private List<Country> countries = new ArrayList<Country>();
	private List<BusinessType>businessTypes = new ArrayList<BusinessType>();
	private List<Directorate>directorates = new ArrayList<Directorate>();
	private List<Contact> contacts = new ArrayList<Contact>();
	DirectorateDao directorateDao = new DirectorateDaoImp();
	BusinessTypeDao businessTypeDao = new BusinessTypeDaoImpl();
	OrganisationDao organisationDao = new OrganisationDaoImpl();
	ContactDao contactDao = new ContactDaoImpl();
	CountryDao countryDao = new CountryDaoImpl();
	
	
	public String getDirectorateName() {
		return directorateName;
	}
	public void setDirectorateName(String directorateName) {
		this.directorateName = directorateName;
	}
	public String getDirectorateShortDescription() {
		return directorateShortDescription;
	}
	public void setDirectorateShortDescription(String directorateShortDescription) {
		this.directorateShortDescription = directorateShortDescription;
	}
	public Long getContactId() {
		return contactId;
	}
	public void setContactId(Long contactId) {
		this.contactId = contactId;
	}
	public Long getLeadContactId() {
		return leadContactId;
	}
	public void setLeadContactId(Long leadContactId) {
		this.leadContactId = leadContactId;
	}
	public Long getOrganisationId() {
		return organisationId;
	}
	public void setOrganisationId(Long organisationId) {
		this.organisationId = organisationId;
	}
	public String getAddressLine1() {
		return addressLine1;
	}
	public void setAddressLine1(String addressLine1) {
		this.addressLine1 = addressLine1;
	}
	public String getAddressLine2() {
		return addressLine2;
	}
	public void setAddressLine2(String addressLine2) {
		this.addressLine2 = addressLine2;
	}
	public String getAddressLine3() {
		return addressLine3;
	}
	public void setAddressLine3(String addressLine3) {
		this.addressLine3 = addressLine3;
	}
	public String getPostcode() {
		return postcode;
	}
	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getCounty() {
		return county;
	}
	public void setCounty(String county) {
		this.county = county;
	}
	public Long getCountry() {
		return country;
	}
	public void setCountry(Long country) {
		this.country = country;
	}
	public Long getBusinessId() {
		return businessId;
	}
	public void setBusinessId(Long businessId) {
		this.businessId = businessId;
	}
	public String getDirectorateFullDescription() {
		return directorateFullDescription;
	}
	public void setDirectorateFullDescription(String directorateFullDescription) {
		this.directorateFullDescription = directorateFullDescription;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public String getFax() {
		return fax;
	}
	public void setFax(String fax) {
		this.fax = fax;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getWebAddress() {
		return webAddress;
	}
	public void setWebAddress(String webAddress) {
		this.webAddress = webAddress;
	}
	public String getCharityNumber() {
		return charityNumber;
	}
	public void setCharityNumber(String charityNumber) {
		this.charityNumber = charityNumber;
	}
	public String getCompanyNumber() {
		return companyNumber;
	}
	public void setCompanyNumber(String companyNumber) {
		this.companyNumber = companyNumber;
	}
	public Long getDirectorateId() {
		return directorateId;
	}
	public void setDirectorateId(Long directorateId) {
		this.directorateId = directorateId;
	}
	public Directorate getDirectorate() {
		return directorate;
	}
	public void setDirectorate(Directorate directorate) {
		this.directorate = directorate;
	}
	public List<Country> getCountries() {
		return countries;
	}
	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}
	public List<BusinessType> getBusinessTypes() {
		return businessTypes;
	}
	public void setBusinessTypes(List<BusinessType> businessTypes) {
		this.businessTypes = businessTypes;
	}
	public List<Directorate> getDirectorates() {
		return directorates;
	}
	public void setDirectorates(List<Directorate> directorates) {
		this.directorates = directorates;
	}
	public List<Contact> getContacts() {
		return contacts;
	}
	public void setContacts(List<Contact> contacts) {
		this.contacts = contacts;
	}



	

	
	
	
	// getter and seter
	
	
}	